package
{
	import flash.filters.GlowFilter;
	
	import org.flixel.FlxG;
	import org.flixel.FlxGroup;
	import org.flixel.FlxSprite;
	import org.flixel.FlxText;
	public class MyPuzzleListing extends FlxGroup
	{
		public static const LISTING_WIDTH:int = 370;
		public static const LISTING_HEIGHT:int = 110;
		
		private var bg:FlxSprite;
		private var titleText:FlxText;
		private var authorText:FlxText;
		private var overlap:Boolean;
		
		// Format will be:
		// 0-map id
		// 1-playerid
		// 2-name
		// 3-contents
		// 4-arrows
		// 5-chickens
		// 6-difficulty
		// 7-tileset
		// 8-rating
		// 9-number of votes
		private var specArray:Array;
		private var hoverFilter:GlowFilter;
		
		public function MyPuzzleListing(_title:String, _author:String, _rating:int, spec:String, x:int, y:int)
		{
			super();
			bg = new FlxSprite();
			bg.makeGraphic(LISTING_WIDTH, LISTING_HEIGHT, 0x000000, true);
			bg.drawRoundRect(0, 0, LISTING_WIDTH, LISTING_HEIGHT, 20, 0x000000);
			bg.x = x;
			bg.y = y;
			add(bg);
			
			specArray = spec.split(":");
			
			var timesPlayed:FlxText = new FlxText(x+105, y + 40, 25, specArray[11], false);
			timesPlayed.setFormat("Courier New", 20, 0xFFFFFF, "left", 0, true);
			var timesBeaten:FlxText = new FlxText(x+105, y + 70, 25, specArray[10], false);
			timesBeaten.setFormat("Courier New", 20, 0xFFFFFF, "left", 0, true);
			
			var t:FlxText = new FlxText(x+5, y + 40, 75, "Played:", false);
			t.setFormat("Courier New", 14, 0xFFFF00, "right");
			var t1:FlxText = new FlxText(x+5, y + 70, 75, "Beaten:", false);
			t1.setFormat("Courier New", 14, 0xFFFF00, "right");
			this.add(t);
			this.add(t1);
			this.add(timesPlayed);
			this.add(timesBeaten);
			
			titleText = new FlxText(x + 5, y + 5, LISTING_WIDTH/2, _title, false);
			titleText.setFormat("Courier New", 20, 0xFFFF00);
			add(titleText);
			
			drawStars(_rating);
			hoverFilter = new GlowFilter(0xFFFFFF, 0.6, 10, 10, 3);
		}
		
		/**
		 * Draws the 5 stars
		 */
		private function drawStars(rating:int):void {
			var xPos:int = (bg.x + bg.width) - (30*5) - 10;
			for (var i:int = 0; i < 5; i++) {
				var star:Class = (i + 1 <= rating) ? Res.StarFull : Res.StarEmpty;
				add(new FlxSprite(xPos, bg.y + 10, star));
				xPos += 30;
			}
		}
	}
}